using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using emp.Model.SysManage;
using emp.BLL.SysManage;
using emp.Utility;

namespace emp.ProcessFlow.SysManage
{
    public class RoleController
    {
        private const string URL_DEFAULT = "role_list.aspx";

        /// <summary>
        /// Default constructor
        /// </summary>
        public RoleController()
        {
        }


        public bool CreateRole(RoleInfo newRoleInfo)
        {
            try
            {
                // Creata a new business logic tier
                Role func = new Role();
                // Call the insert method
                if (func.Insert(newRoleInfo) < 1)
                {
                    return false;
                }

                //Finally forward to the welcome page
                HttpContext.Current.Response.Redirect(URL_DEFAULT, true);
            }
            catch (Exception error)
            {
                string sMethod = "emp.ProcessFlow.RoleController.SysManage.CreateUser(UserInfo newUserInfo)";
                EventsLog.WriteLog(error, sMethod);
                return false;
            }

            return true;
        }

        public bool UpdateRole(RoleInfo updatedRoleInfo, string sCurPage)
        {
            try
            {
                // Create the business logic tier
                Role func = new Role();

                // Call the udpate method
                if (func.Update(updatedRoleInfo) < 1)
                {
                    return false;
                }

                //Redirect the user to the my account page
                HttpContext.Current.Response.Redirect(URL_DEFAULT + "?page=" + sCurPage, true);
                
            }
            catch (Exception error)
            {
                string sMethod = "emp.ProcessFlow.RoleController.SysManage.UpdateRole(RoleInfo updatedRoleInfo, string sCurPage)";
                EventsLog.WriteLog(error, sMethod);
                return false;
            }
            return true;
        }

        public bool DeleteRole(int iRoleID, string sCurPage)
        {
            try
            {
                Role func = new Role();
                if (func.Delete(iRoleID) < 1)
                {
                    return false;
                }
                HttpContext.Current.Response.Redirect(URL_DEFAULT + "?page=" + sCurPage, true);
                return true;
            }
            catch (Exception error)
            {
                string sMethod = "emp.ProcessFlow.RoleController.SysManage.UpdateRole(RoleInfo updatedRoleInfo, string sCurPage)";
                EventsLog.WriteLog(error, sMethod);
                return false;
            }
        }
    }
}
